<!doctype html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
        <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
        <title>index</title>
        <link rel="stylesheet" type="text/css" href="../../css/api.css" />
        <link rel="stylesheet" type="text/css" href="../../css/style.css" />
        <link rel="stylesheet" type="text/css" href="../../css/weui.min.css">
        <script type="text/javascript" src="../../script/jquery-1.10.2.min.js"></script>
        <script type="text/javascript" src="../../script/api.js"></script>
    </head>
    <body>
        <div class="container" id="container">
             <div class="cell">
                <div class="hd">
                    <h1 class="page_title"></h1>
                </div>
            </div>
            <div class="weui_cells_title">用户登录</div>
                <div class="weui_cells weui_cells_form">
                    <div class="weui_cell">
                        <div class="weui_cell_hd"><label class="weui_label">用户名</label></div>
                        <div class="weui_cell_bd weui_cell_primary">
                            <input id="txtUserName" class="weui_input" placeholder="请输入用户名"/>
                        </div>
                    </div>
                    <div class="weui_cell">
                        <div class="weui_cell_hd"><label class="weui_label">密码</label></div>
                        <div class="weui_cell_bd weui_cell_primary">
                            <input id="txtUserPwd" class="weui_input" type="password" placeholder="请输入密码"/>
                        </div>
                    </div>
                </div>
            <div class="weui_cells_tips" id="divAlert"><span id="spAlert" class="fontRed">&nbsp;</span></div>
            <div class="space">&nbsp;</div>
            <div class="mainbutton">
                <a class="weui_btn weui_btn_primary" href="javascript:;" id="btnLogin" onclick="SaveInfo()"> 确 定 </a>
            </div>
            <div class="space"></div>
            <div class="space"></div>
            <div class="space" style="text-align: right;">
                <a style="padding-right: 20px; color:#225fba; cursor:hander" onclick="SetServerUrl()">设置</a>
            </div>
        </div>
    </body>
</html>
<script type="text/javascript">
    apiready = function() {
        $api.fixStatusBar($api.dom('header'));
        api.setStatusBarStyle({
            style: 'dark',
            color: '#6ab494'
        });
    };

    function SetServerUrl()
    {
         api.openWin({
            name: 'win_setup',
            url: '../setup/win_setup.html',
        });
    }

    function OpenMain() {
        api.closeWin({
            name: 'main',
            url: '../../main.html',
        })

        api.openWin({
            name: 'main',
            url: '../../main.html',
            bounces: false,
            delay: 200
        });
    }

    function SaveInfo() {
        var vUserName=$("#txtUserName").val();
        var vUserPwd=$("#txtUserPwd").val();

        if(vUserName == "")
        {
            $("#divAlert").show();
            $("#spAlert").html("请输入用户名！");
            return;
        }

        if(vUserPwd == "")
        {
            $("#divAlert").show();
            $("#spAlert").html("请输入密码！");
            return;        
        }
        
        $("#divAlert").show();
        $("#spAlert").css("color","green");
        $("#spAlert").html("正在登录...");

        var vUrlWrite = $api.getStorage('ServerUrlWrite');

        api.ajax({
                url: vUrlWrite + '/WcfServices/LoginRYXX/'+ vUserName + '/'+vUserPwd,
                method: 'post',
                contentType: "application/json",
            }, function(ret, err) {
                if(ret.LoginRYXXResult.IsSuccess == true)
                {
                    $api.setStorage('UserCHName', ret.LoginRYXXResult.Data.CHNAME);
                    $api.setStorage('UserName', vUserName);
                    $api.setStorage('UserSFZH', ret.LoginRYXXResult.Data.IDCARD);
                    $api.setStorage('UserType', ret.LoginRYXXResult.Data.USERROLES);
                    api.openWin({
                    name: 'win_home',
                    url: '../win_home.html',
                    bounces: false,
                    delay: 200
                    });
                }
                else
                {
                    $("#spAlert").css("color","red");
                    $("#spAlert").html(ret.LoginRYXXResult.Message);
                }
           });
    }
</script>

